package com.ge.boot08rpc.config;

import com.ge.boot08rpc.Interface.HttpInterface;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

/**
 * 测试 Http Interface
 */

@Configuration
public class HttpInterfaceConfig {

    @Bean
    HttpServiceProxyFactory proxyFactory(@Value("${HttpInterface.auth}") String auth) {
        WebClient client = WebClient.builder()
                .defaultHeader("Authorization", auth)
                .build();
        return HttpServiceProxyFactory
                .builderFor(WebClientAdapter.create(client))
                .build();
    }

    @Bean
    HttpInterface factoryClient(HttpServiceProxyFactory proxyFactory) {
        return proxyFactory.createClient(HttpInterface.class);
    }

}
